const os = require('os');
// 获取本地IP地址的函数
const getLocalIP = function () {
  const interfaces = os.networkInterfaces();
  for (const devName in interfaces) {
    const iface = interfaces[devName];

    for (let i = 0; i < iface.length; i++) {
      const alias = iface[i];
      if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
        return alias.address;
      }
    }
  }

  return '127.0.0.1'; // 返回回环地址作为默认值
}

module.exports = getLocalIP;